<?php
declare (strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;

class TimerTask extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('timer:run')
            ->setDescription('the timer:run command')
            ->addArgument('action', Argument::REQUIRED, '任务动作：clean(清理)、sync(同步)、backup(备份)');
    }


    protected function execute(Input $input, Output $output)
    {
        $action = $input->getArgument('action');

        $timer_app = new \catchAdmin\model\Timer();

        if (!(new \ReflectionClass($timer_app))->hasMethod($action)) {
            echo $action . ' 方法不存在';

            return;
        }

        $timer_app->$action();
    }

}
